/**
 * Created by shitao on 15/10/17.
 */

(function () {
    // 创建service对象
    angular.module('my-tabs.services')
        .factory('appService', appService);
    // 申明依赖
    appService.$inject = ['appApi', 'sessionService'];

    function appService(appApi, session) {

        var mines = [];

        return {

            all: function () {
                var promise;

                if (session.isSignIn()) {
                    promise = appApi.getApps(session.getSignInUser().id);
                } else {
                    promise = appApi.getDefaultApps();
                }
                return promise.done(function (datas) {
                    mines.length = 0;
                    mines.splice(0, datas);
                });
            },

            get: function (appId) {
                for (var i = 0; i < mines.length; i++) {
                    if (mines[i].appId === parseInt(appId)) {
                        return mines[i];
                    }
                }
                return null;
            }

        };
    };
})();

/**
 * Created by jimshi0912 on 15/11/2.
 */
/**
 * Created by shitao on 15/10/17.
 */
(function () {
    angular.module('my-tabs.services')
        .factory('sessionService', sessionService);

    sessionService.$injector = ['_'];

    function sessionService(_) {

        var signInUser = {};

        var sessionService = {
            doSignIn: doSignIn,
            getSignInUser: getSignInUser,
            isSignIn: isSignIn
        };

        function doSignIn() {

        };

        function getSignInUser() {
            return signInUser;
        };

        function isSignIn() {
            return _.isEmpty(signInUser) ? false : true;
        };

        return sessionService;

    }
})();
